﻿using DocumentFormat.OpenXml.Lite.Helper;
using DocumentFormat.OpenXml.Lite.WordprocessingML.Word.Types;
using DocumentFormat.OpenXml.Lite.Xml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace DocumentFormat.OpenXml.Lite.WordprocessingML.Word.ParagraphProperties
{
    [XmlRoot("framePr", Namespace = Constants.WordMain)]
    public class FrameProperties : XmlSerializable, IParagraphPropElement
    {
        [Optional]
        [XmlAttribute("dropCap", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<ST_DropCap> DropCapFrame { get; set; }

        [Optional]
        [XmlAttribute("lines", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<int> DropCapVerticalHeight { get; set; }

        [Optional]
        [XmlAttribute("w", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<uint> FrameWidth { get; set; }

        [Optional]
        [XmlAttribute("h", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<uint> FrameHeight { get; set; }

        [Optional]
        [XmlAttribute("vSpace", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<uint> VerticalPadding { get; set; }

        [Optional]
        [XmlAttribute("hSpace", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<uint> HorizontalPadding { get; set; }

        [Optional]
        [XmlAttribute("wrap", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<ST_Wrap> Wrap { get; set; }

        [Optional]
        [XmlAttribute("hAnchor", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<ST_HAnchor> HorizontalPositioning { get; set; }

        [Optional]
        [XmlAttribute("vAnchor", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<ST_VAnchor> VerticalPositioning { get; set; }

        [Optional]
        [XmlAttribute("x", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<int> AbsoluteHorizontalPosition { get; set; }

        [Optional]
        [XmlAttribute("xAlign", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<ST_XAlign> RelativeHorizontalPosition { get; set; }

        [Optional]
        [XmlAttribute("y", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<int> AbsoluteVerticalPosition { get; set; }

        [Optional]
        [XmlAttribute("yAlign", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<ST_YAlign> RelativeVerticalPosition { get; set; }

        [Optional]
        [XmlAttribute("hRule", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<ST_HeightRule> HeightType { get; set; }

        /// <summary>
        /// Lock Frame Anchor to Paragraph
        /// </summary>
        [Optional]
        [XmlAttribute("anchorLock", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<ST_OnOff> Lock { get; set; }

        public void Copy(object obj)
        {
            if (obj is FrameProperties)
            {
                this.AbsoluteHorizontalPosition = (obj as FrameProperties).AbsoluteHorizontalPosition;
                this.AbsoluteVerticalPosition = (obj as FrameProperties).AbsoluteVerticalPosition;
                this.DropCapFrame = (obj as FrameProperties).DropCapFrame;
                this.DropCapVerticalHeight = (obj as FrameProperties).DropCapVerticalHeight;
                this.FrameHeight = (obj as FrameProperties).FrameHeight;
                this.FrameWidth = (obj as FrameProperties).FrameWidth;
                this.HeightType = (obj as FrameProperties).HeightType;
                this.HorizontalPadding = (obj as FrameProperties).HorizontalPadding;
                this.HorizontalPositioning = (obj as FrameProperties).HorizontalPositioning;
                this.Lock = (obj as FrameProperties).Lock;
                this.RelativeHorizontalPosition = (obj as FrameProperties).RelativeHorizontalPosition;
                this.RelativeVerticalPosition = (obj as FrameProperties).RelativeVerticalPosition;
                this.VerticalPadding = (obj as FrameProperties).VerticalPadding;
                this.VerticalPositioning = (obj as FrameProperties).VerticalPositioning;
                this.Wrap = (obj as FrameProperties).Wrap;
            }
        }
    }
}
